#include "server.h"
#include "player.h"

Battlefield PlayerB_BF;
char * PlayerBName = "xyz";

// 玩家部署舰艇
int DeploymentB()
{
    for(int i=0;i<M;i++)
        for(int j=0;j<M;j++)
        {
            PlayerB_BF.area[i][j] = 1;
        }
    // add your arrangement, for example:
    PlayerB_BF.area[0][0] = D; PlayerB_BF.area[0][1] = D;
    PlayerB_BF.area[1][0] = S; PlayerB_BF.area[1][1] = S; PlayerB_BF.area[1][2] = S;
    PlayerB_BF.area[2][0] = C; PlayerB_BF.area[2][1] = C; PlayerB_BF.area[2][2] = C;
    PlayerB_BF.area[3][0] = B; PlayerB_BF.area[3][1] = B; PlayerB_BF.area[3][2] = B; PlayerB_BF.area[3][3] = B;
    PlayerB_BF.area[4][0] = A; PlayerB_BF.area[4][1] = A; PlayerB_BF.area[4][2] = A; PlayerB_BF.area[4][3] = A; PlayerB_BF.area[4][4] = A;

    printBF(&PlayerB_BF);
    return 0;
}

static int lasti = 0;
static int lastj = -1;
// 根据上次是否击中确定策略，选择下一个攻击点
// 可以自己创建数据结构记录之前的击中与否信息
int StrategyB()
{
    int i,j;
    // 从服务器端获取上次攻击是否击中信息
    int isHit = BLastHitA();
    //printf("^^^^^^StrategyB: last %d\n", isHit);

    // fire to position (i,j), for example: from left top to right bottom 
    i = lasti;
    j = lastj+1;
    if(j>=M)
    {
        j = 0;
        i = lasti+1;
    }
    // 向(i,j)位置开火
    firetoA(i,j);

    lasti = i;
    lastj = j;

    return 0;
}
